import { Rule } from 'antd/lib/form';
import { RcFile } from 'antd/lib/upload';

export const required = (msg: string): Rule => {
    return {
        required: true,
        message: msg,
    };
};

export const validImageWhenSubmit = (msg: string = '请上传图片'): Rule => {
    return {
        validateTrigger: 'submit',
        validator: (_: any, values: RcFile[] | undefined): Promise<any> => {
            if (values?.length) {
                return Promise.resolve();
            }
            return Promise.reject(msg);
        },
    };
};
